import java.util.Scanner;
//实现数组旋转的一个非常经典且高效的三次反转方法
public class Test {
    public static void temp(int[] nums,int i,int j){
        int tmp;
        while(i < j) {
            tmp = nums[i];
            nums[i] = nums[j];
            nums[j] = tmp;
            i++;
            j--;
        }
    }
    public static void rotate(int[] nums, int k) {
        k %= nums.length;
        temp(nums,0,nums.length-1);
        temp(nums,0,k-1);
        temp(nums,k,nums.length-1);
    }
    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3,4,5,6,7};
        rotate(nums,3);
        for (int i = 0; i < nums.length; i++) {
            System.out.printf("%d ",nums[i]);
        }
    }
}
